%%
clear all

U=1; V=0;
M=16;   N=16;
bases=zeros(M,N);

for x = 1:M
    for y = 1:N
        bases(x,y) = cos((2*pi/N)*U*(x-1))*cos((2*pi/N)*V*(y-1))
    end
end

s=abs(min(min(bases)));
ss=s+bases;
base=ss/max(max(ss));

imshow(base,'InitialMagnification','fit'), colormap(jet);
%%
%clc
%clear all

% generate impulse image
M=16;   N=16;
%base=zeros(M,N);
% a
%base(1:1,1:1)=1;
% b
%base(1:16,1:16)=0.2;
% c
%base(1:8,1:4)=1;

% FFT 2-D
baseFFT=fft2(base);
% IFFT 2-D
baseBack=ifft2(baseFFT);

% c
baseBackCrop =imcrop(baseBack,[0 0 16 16]);

phase=angle(baseFFT)

% subplot(2,2,1), imshow(base); colorbar, title(['Original'])
% subplot(2,2,2), imshow(abs(baseFFT)); colorbar, title(['Magnitude FFT2 of Original'])
% subplot(2,2,3), imshow(real(baseBack)); colorbar, title(['IFFT2 of FFT2 Original'])
% subplot(2,2,4), imshow(angle(baseFFT),[-pi pi]); colorbar, title(['Phase FFT2 of Original'])

% c
figure(1),
subplot(2,2,1), imshow(base,'InitialMagnification','fit');colormap(jet); colorbar, title(['Original'])
subplot(2,2,2), imshow(abs(baseFFT),'InitialMagnification','fit');colormap(jet); colorbar, title(['Magnitude FFT2 of Original'])
subplot(2,2,3), imshow(real(baseBackCrop),'InitialMagnification','fit');colormap(jet); colorbar, title(['IFFT2 of FFT2 Original'])
subplot(2,2,4), imshow(angle(baseFFT),[-pi pi],'InitialMagnification','fit');colormap(jet); colorbar, title(['Phase FFT2 of Original'])
figure(2),surf(abs(fftshift(baseFFT))); colormap(HSV);%axis([0 64 0 64 0 35])
